//
//  XMainViewController.m
//  iPlan
//
//  Created by 侯伟 on 2021/8/29.
//

#import "XMainViewController.h"
#import "XNavigationViewController.h"
#import "XNoteBookListViewController.h"
#import "XPlanListViewController.h"
#import "XClockInListViewController.h"
#import "XMineViewController.h"

#import "RFaceCheckRequest.h"

@interface XMainViewController ()

@end

@implementation XMainViewController

- (void)loadView{
    [super loadView];
    
    //去除tabbar黑色线
    self.tabBar.barStyle = UIBarStyleBlack;
    self.tabBar.tintColor = COLOR_THEME_A;
    self.tabBar.barTintColor = COLOR_WHITE;
    self.tabBar.translucent = NO;
    
    //设置阴影
    self.tabBar.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    self.tabBar.layer.shadowOffset = CGSizeMake(0, -1);
    self.tabBar.layer.shadowOpacity = 0.3;
    
    if (@available(iOS 13.0, *)) {
        UITabBarAppearance *standardAppearance = [UITabBarAppearance new];
        [standardAppearance configureWithOpaqueBackground];
        standardAppearance.backgroundColor = COLOR_WHITE;
        self.tabBar.standardAppearance = standardAppearance;
        if (@available(iOS 15.0, *)) {
            self.tabBar.scrollEdgeAppearance = standardAppearance;
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadSubControllers];
    
    [self requestData];
}

- (void)loadSubControllers {
    
    NSMutableArray* tabBarControllers = [NSMutableArray array];


    // 计划
    XPlanListViewController* countController = [XPlanListViewController new];
    XNavigationViewController* countNav = [[XNavigationViewController alloc] initWithRootViewController:countController];
    UITabBarItem* countItem = [[UITabBarItem alloc] initWithTitle:@"计划" image:[UIImage imageNamed:@"a_tabar_list_n"] selectedImage:[UIImage imageNamed:@"a_tabar_list_h"]];
    countItem.tag = 1001;
    countNav.tabBarItem = countItem;
    [tabBarControllers addObject:countNav];
    
    //记事本
    XNoteBookListViewController* noteBookController = [XNoteBookListViewController new];
    XNavigationViewController* noteBookNav = [[XNavigationViewController alloc] initWithRootViewController:noteBookController];
    UITabBarItem* noteBooItem = [[UITabBarItem alloc] initWithTitle:@"记事本" image:[UIImage imageNamed:@"a_tabar_notebook_n"] selectedImage:[UIImage imageNamed:@"a_tabar_notebook_h"]];
    noteBooItem.tag = 1002;
    noteBookNav.tabBarItem = noteBooItem;
    [tabBarControllers addObject:noteBookNav];


    // 打卡
    XClockInListViewController* clockController = [XClockInListViewController new];
    XNavigationViewController* clockNav = [[XNavigationViewController alloc] initWithRootViewController:clockController];
    UITabBarItem* clockItem = [[UITabBarItem alloc] initWithTitle:@"打卡" image:[UIImage imageNamed:@"a_tabar_clock_n"] selectedImage:[UIImage imageNamed:@"a_tabar_clock_h"]];
    clockItem.tag = 1003;
    clockNav.tabBarItem = clockItem;
    [tabBarControllers addObject:clockNav];

    //我的
    XMineViewController* mineController = [XMineViewController new];
    XNavigationViewController* mineNav = [[XNavigationViewController alloc] initWithRootViewController:mineController];

    UITabBarItem* mineItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"a_tabar_mine_n"] selectedImage:[UIImage imageNamed:@"a_tabar_mine_h"]];
    mineItem.tag = 1004;
    mineNav.tabBarItem = mineItem;
    [tabBarControllers addObject:mineNav];

    [self setViewControllers:tabBarControllers animated:NO];
}

- (void)requestData{
    //getEtc 3-a 4-b
    RFaceCheckRequest* request = [RFaceCheckRequest new];
    [RequestOperation request:request quite:YES callBack:^(HResponse * _Nullable response) {
        [response success:^(NSArray*  _Nonnull data) {
            if(data.count != 3){
                [[NSNotificationCenter defaultCenter] postNotificationName:kChangeNotification object:NULL userInfo:NULL];
            }
        }];
    }];
}
@end
